package com.wan.data.redis;

import com.wan.IKit;
import com.wan.data.redis.jedis.JedisManager;
import com.wan.data.redis.jedis.JedisSetting;
import redis.clients.jedis.HostAndPort;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class RedisKit extends IKit {

    @Override
    public void init() {
        JedisSetting jedisSetting = groupSetting.toBean(JedisSetting.class);
        String[] hosts = groupSetting.getStrings("hosts");
        List<HostAndPort> hostAndPorts = Arrays.stream(hosts).map(HostAndPort::from).collect(Collectors.toList());
        jedisSetting.setHostAndPorts(hostAndPorts);
        JedisManager.load(jedisSetting);
    }

    @Override
    public void shutdown() {
    }
}
